package com.hzhr.iot.device.controller;

import com.hzhr.iot.core.annotation.ApiImplicitInternalParams;
import com.hzhr.iot.core.annotation.Author;
import com.hzhr.iot.core.dto.ResponseExceptionDto;
import com.hzhr.iot.core.exception.ServiceException;
import com.hzhr.iot.device.controller.base.BaseController;
import com.hzhr.iot.device.model.flowMeter.*;
import com.hzhr.iot.device.model.nbMeter.NbMeterDeleteModel;
import com.hzhr.iot.device.model.nbMeter.NbMeterGetModel;
import com.hzhr.iot.device.model.nbMeter.NbMeterPostModel;
import com.hzhr.iot.device.model.nbMeter.NbMeterPutModel;
import com.hzhr.iot.device.service.FlowMeterService;
import com.hzhr.iot.device.service.NbMeterService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.Map;

@Api(tags = "NbMeter", description = "NB物联表")
@RestController
@RequestMapping(value = "")
public class NbMeterController extends BaseController {
    @Autowired
    NbMeterService nbMeterService;

    //region /nb-meters POST
    //region swagger响应码 : post
    @ApiResponses({
            @ApiResponse(code = 200, message = "成功"),
            @ApiResponse(code = 403, message = "----异常代码 : 201  \n----异常类型 : 业务流程异常  \n----异常业务 : 验证NB物联网表的IMEI号  \n----异常说明 : IMEI号已存在  \n\n", response = ResponseExceptionDto.class),
    })
    //endregion
    //region swagger说明 : post
    @ApiOperation(value="新增NB表", notes="新增NB表  \n1. 验证NB物联网表的IMEI号：如果存在相同IMEI号的物联网设备，抛出异常“IMEI号已存在”  \n2. 新增NB物联网表  \n3. 通知物联网平台创建该设备档案  \n4. 返回信息  \n",produces = "application/json")
    //endregion
    //region swagger参数 : post
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "令牌",required = true, dataType = "string", paramType = "header"),
    })
    @ApiImplicitInternalParams({
            @ApiImplicitParam(name = "_token", value = "令牌",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-id", value = "用户编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-code", value = "用户代码",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-name", value = "用户名",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-company-id", value = "公司编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-dept-id", value = "部门编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-type", value = "用户类型(关联: common_service.options.code, typeCode = 'USER_TYPE')",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-id", value = "交易流水号",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-type", value = "交易类型",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-access-mode", value = "访问模式 0:一般 1:全局",defaultValue = "0", required = false, dataType = "int", paramType = "header"),
    })
    //endregion
    //region 请求 : post
    @RequestMapping(value = "/nb-meters", method = RequestMethod.POST)
    //endregion
    @Author
    public ResponseEntity<NbMeterGetModel> post(@RequestParam @ApiIgnore Map<String, Object> query,
                                                @RequestBody NbMeterPostModel body) throws ServiceException {
        NbMeterGetModel responseBody = nbMeterService.post(initHeader(), query, body);
        return new ResponseEntity<>(responseBody, HttpStatus.OK);
    }
    //endregion

    //region /nb-meters/{nbMeterId} PUT
    //region swagger响应码 : put
    @ApiResponses({
            @ApiResponse(code = 200, message = "成功"),
            @ApiResponse(code = 403, message = "----异常代码 : 201  \n----异常类型 : 业务流程异常  \n----异常业务 : 获取NB物联网表  \n----异常说明 : NB物联网表不存在  \n\n----异常代码 : 202  \n----异常类型 : 业务流程异常  \n----异常业务 : 验证NB物联网表是否在iot平台上完成注册  \n----异常说明 : 该NB物联网表还未在iot平台上完成注册  \n\n", response = ResponseExceptionDto.class),
    })
    //endregion
    //region swagger说明 : put
    @ApiOperation(value="修改NB表", notes="修改NB表  \n1. 获取NB物联网表：查询NB物联网表，如果不存在，抛出异常“NB物联网表不存在”  \n2. 验证NB物联网表是否在iot平台上完成注册：如果该NB物联网表没有iot平台设备编号，抛出异常“该NB物联网表还未在iot平台上完成注册”  \n3. 修改NB物联网表  \n4. 通知iot平台更新该设备档案  \n5. 返回信息  \n",produces = "application/json")
    //endregion
    //region swagger参数 : put
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "令牌",required = true, dataType = "string", paramType = "header"),
    })
    @ApiImplicitInternalParams({
            @ApiImplicitParam(name = "_token", value = "令牌",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-id", value = "用户编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-code", value = "用户代码",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-name", value = "用户名",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-company-id", value = "公司编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-dept-id", value = "部门编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-type", value = "用户类型(关联: common_service.options.code, typeCode = 'USER_TYPE')",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-id", value = "交易流水号",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-type", value = "交易类型",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-access-mode", value = "访问模式 0:一般 1:全局",defaultValue = "0", required = false, dataType = "int", paramType = "header"),
    })
    //endregion
    //region 请求 : put
    @RequestMapping(value = "/nb-meters/{nbMeterId}", method = RequestMethod.PUT)
    //endregion
    @Author
    public ResponseEntity<NbMeterGetModel> put(@PathVariable("nbMeterId") Integer nbMeterId,
                                               @RequestParam @ApiIgnore Map<String, Object> query,
                                               @RequestBody NbMeterPutModel body) throws ServiceException {
        NbMeterGetModel responseBody = nbMeterService.put(initHeader(), nbMeterId, query, body);
        return new ResponseEntity<>(responseBody, HttpStatus.OK);
    }
    //endregion

    //region /nb-meters/{nbMeterId} DELETE
    //region swagger响应码 : delete
    @ApiResponses({
            @ApiResponse(code = 200, message = "成功"),
            @ApiResponse(code = 403, message = "----异常代码 : 201  \n----异常类型 : 业务流程异常  \n----异常业务 : 判断NB表是否具备删除条件  \n----异常说明 : 该NB物联网表不具备删除条件  \n\n", response = ResponseExceptionDto.class),
    })
    //endregion
    //region swagger说明 : delete
    @ApiOperation(value="删除NB表", notes="删除NB表  \n1. 判断NB表是否具备删除条件：  \n 如果该NB表拥有下级采集设备，无法删除；  \n2. 删除NB物联网表  \n3. 如果该NB物联网表在iot平台上完成了注册，通知iot平台删除该设备档案  \n4. 返回信息  \n",produces = "application/json")
    //endregion
    //region swagger参数 : delete
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "令牌",required = true, dataType = "string", paramType = "header"),
    })
    @ApiImplicitInternalParams({
            @ApiImplicitParam(name = "_token", value = "令牌",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-id", value = "用户编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-code", value = "用户代码",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-name", value = "用户名",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-company-id", value = "公司编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-dept-id", value = "部门编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-type", value = "用户类型(关联: common_service.options.code, typeCode = 'USER_TYPE')",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-id", value = "交易流水号",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-type", value = "交易类型",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-access-mode", value = "访问模式 0:一般 1:全局",defaultValue = "0", required = false, dataType = "int", paramType = "header"),
    })
    //endregion
    //region 请求 : delete
    @RequestMapping(value = "/nb-meters/{nbMeterId}", method = RequestMethod.DELETE)
    //endregion
    @Author
    public ResponseEntity<NbMeterDeleteModel> delete(@PathVariable("nbMeterId") Integer nbMeterId,
                                                     @RequestParam @ApiIgnore Map<String, Object> query) throws ServiceException {
        NbMeterDeleteModel responseBody = nbMeterService.delete(initHeader(), nbMeterId, query);
        return new ResponseEntity<>(responseBody, HttpStatus.OK);
    }
    //endregion
}

















































































































































































































































































































































































































































































































































































































































































